$(function(){
	$.ax(
		"resource/getAllmessage",
		null,
		null,
		"get",
		"json",
		function(data){
			var str = "";
			if(data.messageCode===200){
				var obj = data.sysdata.mss;
				for(var i = 0 ; i <obj.length;i++){
					var time = getMyDate(obj[i].createtime);
						
					str = str+ "<li><ul class='row'><li class='col-lg-1 col-md-1 col-sm-1 left-img'><span class='glyphicon glyphicon-user'></span></li><li class='col-lg-11 col-md-11 col-sm-11 right-text'><p>匿名<span>"+time+"</span></p><p>"+obj[i].content+"</p></li></ul></li>";
					
				}
				$(".mess-box").html(str);
			}
		},
		function(){
			alert("error");
		}
	);
	//文本框获取焦点，提示文字显示
	$(".popover").hide();
	$("#message").focus(function(){
		$(".popover").fadeIn();
	});
	$("#message").blur(function(){
		$(".popover").fadeOut();
	});
	$(".popover .popover-content").click(function(){
		var newText = $(this).text().trim();
		$("#message").val(function(i,text){
			return text+newText;
		})
		$("#message").blur();
	})
	//点击留言按钮
	$("#spe .button").click(function(){ 
		var txt = $("#message").val().trim();
		if(txt==""){
		
			$("#messText").html('不能为空');
			
		}else{
			initialize();

			$("#messText").html("");
			$.ax(
			"resource/addmessage",
			"content="+txt,
			null,
			"post",
			"json",
			function(data){
				subSomething();
				alert("留言发送成功！");
				window.location.href=window.location.href;
			},
			function(){
				subSomething();
				alert("error");
			},
			function(){
				$("#spe .button").css({"background-color":"#ccc"});
				//不可用
				$("#spe input").attr("disabled","disabled");
				$("#loading").css({"display":"block"});
			}
		);
			
		}
	})
})



function loadXMLDoc(tex)
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	{
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		// IE6, IE5 浏览器执行代码
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			window.location.href=window.location.href;
		}
	}
	xmlhttp.open("POST","resource/addmessage",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send(tex);
}
